<template>
    <div>
        <setHeader title="申请列表"></setHeader>
        <div class="content" style="margin-bottom: 0;">
            <!-- 新圈友申请列表 -->
            <div class="business_lists main-application" v-for="(list, index) in CompanyList" :key="index">
                <div class="business_left" style="margin-left: 0.1rem;">
                    <img :src="list.log_img" v-if="list.log_img != null">
                    <img src="../common/images/youquan.png" v-else/>
                </div>
                <div class="business_desc" style="width: 3.6rem; margin-left: 0;">
                    <h5>{{list.name}}</h5>
                    <p style="width: 3.6rem !important;">{{list.message}}</p>
                </div>
                <div class="btn_small_red">
                    <!--  v-if="list.j_status == 2" -->
                    <button @click="Audit(list)" v-if="list.j_status == 2">同意</button>
                    <!-- <button @click="agreeInfo(list,2)" v-if="list.j_status == 2">拒绝</button> -->
                    <button v-if="list.j_status == 1">已同意</button>
                    <!-- <button v-if="list.j_status == 2" style="background-color: #fff; color: #999; border: 1px solid #999;">已拒绝</button> -->
                </div>
            </div>
        </div>
        <mt-popup
            v-model="popupVisible"
            position="bottom">
        <ul> 
            <li style="text-align: left;" :style="list.style" v-for="list in UcompanyList" @click="JoinCompany(list)" :key="list.id">{{list.name}}</li>
        </ul>
        </mt-popup>
    
    </div>
</template>

<script>
import setHeader from '../public/setHeader.vue';
import {createGroup,friendList} from '../api/api'
import IndustryLinkage from '@/components/industry_linkage';
// import { applyList } from '../api/api';
    export default {
        data() {
            return {
                popupVisible:false,
                CompanyList: [],
                /*CompanyList:[
                    {
                        name: '耐思智慧',
                        description: '耐思智慧得到餐饮耐思智慧饮耐思智慧耐思'
                    },
                    {
                        name: '耐思智慧',
                        description: '耐思智慧得到餐饮耐思智慧饮耐思智慧耐思'
                    },
                ],*/
                isShow: true,
                cid: '',
                importFileUrl: this.$path,
                agereeShow: true,
                refuseShow: true,
                agreebtn: '同意',
                refusebtn: '拒绝',
                circlelist: {
                    // userId: '',
                    // cid: '',
                    // check_userId: '',
                    // reject: '',
                    chid: ''
                },
                access_token: '',
                userInfo: '',
                UcompanyList:[],
               
            }
        },
        components: {
            setHeader,
            IndustryLinkage
        },
        created() {
            let that = this;
            that.userInfo = window.localStorage.getItem('userInfo');
            that.userInfo = JSON.parse(that.userInfo);
        },
        mounted() {
            // let that = this;
            // var user = Promise.resolve(this.getUserInfo())
            // user.then(
            //     function (result) { 
            //     that.userInfo = result;
            // })
            
            this.cid = window.localStorage.getItem('paicheNo');
            this.access_token = window.localStorage.getItem('access_token');
        //获取当前圈子的企业
            this.getUserEnterprise();
            
        //获取圈子的组织架构
            this.getAuthriList();
        },
        methods: {
            //获取圈子中的企业
            getUserEnterprise() {
                let that = this;
                // let cid = this.cid;
                // this.$fetch(that.$path+'/api.php/Circle/getCircleCompanyList',{cid:cid})
                // .then((res) => {
                //     // console.log('====', res.data);
                //     // that.CompanyList = res.data.list;
                // })
                that.$fetch(that.$path + '/api.php/Circle/getJoinList',{cid:that.cid}).then((res) => {
                    console.log('审核圈子', res);
                    if(res.code == 200) {
                        console.log(res.data);
                        that.CompanyList = res.data;
                        res.data.forEach(item => {
                            // that.circlelist.check_userId = item.user_id;
                            // item.reject = that.circlelist.reject;
                            // console.log('item.check', item.check)
                            that.circlelist.chid = item.chid;
                            // console.log('444', item.chid);
                        });
                    }
                })
            },
            //获取当前企业的所有职位信息
            getAuthriList:function(){
                let that = this;
                // let company_id = that.userInfo.company_id;
                // console.log('company_id', company_id);
                this.$fetch(
                    that.$path+'/index.php/api/circle/getCircleAuthi',{cid:that.cid})
                    .then((res) => {
                        console.log('圈子职位', res);
                        if(res.code == 200) {
                            let count = res.data.length;
                            if(count == 1){
                                that.showss = true;
                                that.architeName= res.data[0].name;
                                that.company_id = res.data[0].id;
                            }else{
                                that.architeNames= '请点击选择职位';
                                that.showss = false;
                                that.showsss = true;
                                that.UcompanyList = res.data;
                                that.UcompanyList.forEach((element,index) => {
                                    if(element.level == 1) {
                                        that.UcompanyList[index].style = 'padding-left: 0.2rem';
                                    }else if(element.level == 2){
                                        that.UcompanyList[index].style = 'padding-left: 0.6rem';
                                    }else if(element.level == 3){
                                        that.UcompanyList[index].style = 'padding-left: 1rem';
                                    }
                                });
                            }                        
                        }
                })
            },
            //审核
            Audit(val) {
                console.log('001',val);
                this.check_info = val;
                this.popupVisible = true;
                // this.check_id = val.uid;
                // this.departname = val.d_name;
                // this.departId = val.architeId;
                // 弹框出现
                this.show = true;
                this.stateShow = true;
            },
            //选择组织架构
            JoinCompany(list){
                this.agreeInfo(list);
            },
            
            //点击同意与否
            agreeInfo(list){
                let that = this;
                // console.log('---',list);return false;
                // that.circlelist.userId = that.userInfo.uid;
                // that.circlelist.check_userId = list.user_id;
                // that.circlelist.chid = reject;
                // console.log('uid',list.user_id)
                // console.log('reject',reject)
                that.$fetch(that.$path + '/api.php/Circle/checkJoin', {cid:that.cid,chid:that.check_info.chid,depId:list.id,depName:list.name}).then((res) => {
                    // console.log('审核圈子22', res);return false;
                    if(res.code == 200) {
                        this.popupVisible = false;
                        //加入群聊
                        that.$store.commit('setPage', 2);//设置需要预请求的参数
                        //返回群聊id和0
                        console.log('99',list.uid);
                    createGroup({name: res.data.c_name,gId:res.data.c_ImId,tId:res.data.im_user,g_type:1}).then(ress => {
                        console.log('a',ress);
                      if (parseInt(ress.status) !== 0) {
                            that.$store.commit('setPage', 1);//设置需要预请求的参数
                            that.getUserEnterprise();
                      }
                    })
                      
                    }
                })
            },
           

        }
    }
</script>

<style>
.main-application:last-child {
    border-bottom: 1px solid #d8d8d8;
}
.main-application .agree_btn {
    background-color: transparent;
    color: #999;
    border: 1px solid #999;
}
</style>
